<!DOCTYPE html>
<html>
<head>
    <include file="public/public_css" />

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <include file="public/header-min" />
    <!-- Left side column. contains the logo and sidebar -->
    <include file="public/left" />
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                文章管理
                <a href="{:U('Admin/Content/addArticle')}" target="_blank"><button type="button" class="btn btn-primary">添加文章</button></a>
            </h1>
            <div class="select-cat breadcrumb">
                <select id="cat" name="cat" class="form-control">
                    <option value="0" selected>全部</option>
                    <volist name="catList" id="vo">
                        <option value="{$vo.cat_id}" <if condition="$cat_id == $vo.cat_id">selected</if>>{$vo._name}</option>
                    </volist>
                  </select>
            </div>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>首页</a></li>
                <li class="active">内容管理</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <!-- Small boxes (Stat box) -->
            <!-- Small boxes (Stat box) -->
            <div class="row">
                <table id="menuList" class="table table-hover">
                    <tr>
                        <th style="text-align:center;">
                          <input id="all" type="checkbox" >
                        </th>
                        <th>排序</th>
                        <th>id</th>
                        <th>标题</th>
                        <th>添加时间</th>
                        <th>分类</th>
                        <th>显示</th>
                        <th>操作</th>
                    </tr>
                    <volist name="list" id="vo">
                         <tr>
                             <td>
                               <input type="checkbox"  name="id[]" value="{$vo.id}">
                             </td>
                             <td>
                                 <input type="text" class="list-order" data-id="{$vo.id}" name="list_order" value="{$vo.list_order}">
                             </td>
                             <td>{$vo.id}</td>
                             <td><a href="{:U('home/index/show', array('id' => $vo.id))}" target="_blank">{$vo.title} <if condition="$vo.po_id gt 0"> <img src="__PUBLIC__/static/images/recommend.png" class="recommend"></if></a></td>
                                 <td>{:date('Y-m-d H:i', $vo.add_time)}</td>
                                 <td>{:get_cat_name($vo.cat_id)}</td>
                                 <td class="is-show-td">
                                      <i  data-id="{$vo.id}" data-is_show="{$vo.is_show}" class="is-show ion-checkmark-circled <if condition="$vo.is_show == 1">is-show1</if>"></i>
                                 </td>

                                 <td>
                                     <a class="delArticle" href="javascript:void(0);" data-id="{$vo.id}" >
                                         <button  type="button" class="btn btn-danger">删除</button>
                                     </a> |
                                     <a class="editArticle"  target="_black" href="{:U('Content/editArticle?', 'id=' .$vo.id)}">
                                         <button type="button" class="btn btn-info">修改</button>
                                     </a>
                                 </td>
                         </tr>
                    </volist>
                </table>

                <div>
                    <button type="button" class="btn btn-danger delArticle" >删除</button>
                    <button id="listOrder"  type="button" class="btn btn-info" >排序</button>
                </div>
                 <div>
                     {$list->render()}
                 </div>
            </div>


        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <include file="public/footer" />

    <!-- Control Sidebar -->

    <!-- /.control-sidebar -->
    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<include file="public/public_js" />

<script>

         //删除文章
    $('.delArticle').click(function(){

          //多选删除
         var checkId = [];
         ($('input[type=checkbox]:checked')).each(function(){
             checkId.push($(this).val());
         });
             //单个删除
        var id = $(this).data('id');
        layer.open({
            btn: ['删除', '取消'],
            yes: function(){
                   //如果是多选
                if(checkId.length > 0){
                     id = checkId;
                }
                    $.ajax({
                        type: 'POST', //GET,POST
                        url: '{$Think.WEB_PATH}/Admin/Content/delArticle?id=' + id,
                        dataType: 'json', //xml,json,script，默认为null
                        success: function (data) {
                            layer.open({
                                type: 1,
                                time: 5000,
                                area: ['200px', '200px'],
                                content: data.msg //服务器返回的消息
                            });
                            setTimeout(function () {
                                window.location.reload();
                            }, 1200);
                        },
                        error: function (event, errorText, errorType) { //错误时调用
                            alert(errorText + errorType);
                        }
                    })

            },
            no: function(){

            },
            fixed: false, //不固定
            maxmin: true,
            content:'确定要删除吗？'
        });
    });

         //全选，全不选
         $('#all').click(function(){
             if(this.checked){
                 $('input[type=checkbox]').prop("checked", true);
             }else{
                 $('input[type=checkbox]').prop("checked", false);
             }
         });
         //排序
         var  list_order = [];
         $("input[name='list_order']").change(function(){
             list_order[$(this).data('id')] = $(this).val();
         });
         $('#listOrder').click(function(){
             list_order = $.toJSON(list_order); //格式化JS数组，将其转化为JSON格式发送到服务
             $.ajax({
                 type: 'POST', //GET,POST
                 url: '{$Think.WEB_PATH}/Admin/Content/orderArticle',
                 data:{list_order:list_order},
                 dataType: 'json', //xml,json,script，默认为null
                 success: function (data) {
                     layer.open({
                         type: 1,
                         time: 5000,
                         area: ['200px', '200px'],
                         content: data.msg //服务器返回的消息
                     });
                     setTimeout(function () {
                         window.location.reload();
                     }, 1200);
                 },
                 error: function (event, errorText, errorType) { //错误时调用
                     alert(errorText + errorType);
                 }
             })
         });
         //显示与不显示
         $('.is-show').click(function(){
             var id = $(this).data('id');
             var is_show = $(this).data('is_show');
             var isShow = $(this);
             $.ajax({
                 type: 'POST',
                 url:"{$Think.WEB_PATH}/Admin/Content/isShowArticle?id=" + id + "&is_show=" + is_show,
                 dataType:'json',
                 success:function(data){
                     if(data.status){
                         if(isShow.hasClass("is-show1")){
                             isShow.removeClass("is-show1");
                             isShow.data('is_show', 0);
                         }else{
                             isShow.addClass("is-show1");
                             isShow.data('is_show', 1);
                         }
                     }
                 }

             });
         });

         //根据分类查看文章
     $("#cat").change(function(){
         $cat_id = $(this).val();
         window.location.href="{$Think.WEB_PATH}/Admin/Content/index?cat_id=" + $cat_id;
     });

</script>
</body>
</html>
